package com.emex.app.stuff.provider;

import com.emex.app.shared.data.Cashbox;
import com.emex.app.shared.data.Orders;
import com.emex.app.shared.data.OrderPayment;
import com.emex.app.shared.data.OrderPosition;
import com.emex.app.shared.ws.OrderWebService;
import com.emex.app.stuff.utils.WebServiceHelper;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.List;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

/**
 *
 * @author Sergey Karavaev
 */
public class OrderDataProvider extends Service {

    private OrderWebService service = null;

    private static OrderDataProvider instance = null;

    /**
     * Constructor
     */
    private OrderDataProvider() throws MalformedURLException {
        super(new URL(WebServiceHelper.getDefault().getWebServiceURL("web", "Order")),
                WebServiceHelper.getDefault().getWebServiceQName("Order"));
        service = getPort(OrderWebService.class);
    }

    /**
     * Get instance of data provider.
     *
     * @return data provider instance
     */
    public static synchronized OrderDataProvider getInstance() {
        if (instance == null) {
            new RequestWebService() {
                @Override
                protected void doRequestBody() throws MalformedURLException {
                    instance = new OrderDataProvider();
                }
            }.doRequest();
        }
        return instance;
    }

    public BindingProvider getBindingProvider() {
        return (BindingProvider) service;
    }

    public int deleteOrderPrimaryKey(Integer id) {
        return service.deleteOrderPrimaryKey(id);
    }

    public Orders insertOrder(Orders record) {
        return service.insertOrders(record);
    }

    public Orders selectOrderByPrimaryKey(Integer id) {
        return service.selectOrderByPrimaryKey(id);
    }

    public Orders updateOrderByPrimaryKey(Orders record) {
        return service.updateOrdersByPrimaryKey(record);
    }

    public List<Orders> getAllClientOrders(Integer clientId) {
        return service.getAllClientOrders(clientId);
    }

    public int deleteOrderPositionByPrimaryKey(Integer id) {
        return service.deleteOrderPositionByPrimaryKey(id);
    }

    public OrderPosition insertOrderPosition(OrderPosition record) {
        return service.insertOrderPosition(record);
    }

    public List<OrderPosition> getOrderPositionByOrderId(Integer clientId) {
        return service.getOrderPositionByOrderId(clientId);
    }

    public OrderPosition selectOrderPositionByPrimaryKey(Integer id) {
        return service.selectOrderPositionByPrimaryKey(id);
    }

    public OrderPosition updateOrderPositionByPrimaryKey(OrderPosition record) {
        return service.updateOrderPositionByPrimaryKey(record);
    }

    public int deleteOrderPaymentByPrimaryKey(Integer id) {
        return service.deleteOrderPaymentByPrimaryKey(id);
    }

    public OrderPayment insertOrderPayment(OrderPayment record) {
        return service.insertOrderPayment(record);
    }

    public List<OrderPayment> getOrderPaymentByOrderId(Integer orderId) {
        return service.getOrderPaymentByOrderId(orderId);
    }

    public OrderPayment selectOrderPaymentByPrimaryKey(Integer id) {
        return service.selectOrderPaymentByPrimaryKey(id);
    }

    public OrderPayment updateOrderPaymentByPrimaryKey(OrderPayment record) {
        return service.updateOrderPaymentByPrimaryKey(record);
    }

    public List<Orders> getOrdersByDate(Date startDate, Date endDate) {
        return service.getOrdersByDate(startDate, endDate);
    }

    public List<OrderPayment> getOrderPaymentsByDate(Date startDate, Date endDate) {
        return service.getOrderPaymentsByDate(startDate, endDate);
    }

    public List<OrderPayment> getOrderPaymentByClientId(Integer clientId) {
        return service.getOrderPaymentByClientId(clientId);
    }    

    public List<OrderPayment> getOrderPaymentsByDateEqualOrGrater(Date date) {
        return service.getOrderPaymentsByDateEqualOrGrater(date);
    }

    public Cashbox insertCashbox(Cashbox record) {
        return service.insertCashbox(record);
    }

    public Cashbox getCashBox() {
        return service.getCashBox();
    }

    public List<Orders> getAllJuridicalClientOrders(Integer jurClientId) {
        return service.getAllJuridicalClientOrders(jurClientId);
    }
}
